# Contributor: Galen Abell <galen@galenabell.com>
# Maintainer: Galen Abell <galen@galenabell.com>
pkgname=libsignal-protocol-c
pkgver=2.3.3
pkgrel=0
pkgdesc="Signal Protocol C Library"
url="https://github.com/signalapp/libsignal-protocol-c"
arch="all"
license="GPL-3.0-only"
makedepends="cmake"
checkdepends="check-dev openssl-dev"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/signalapp/libsignal-protocol-c/archive/v$pkgver.tar.gz"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SHARED_LIBS=True \
		-DBUILD_TESTING=1 \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
		-DCMAKE_C_FLAGS="$CFLAGS" \
		$CMAKE_CROSSOPTS .
	make
}

check() {
	# 92% tests passed, 1 tests failed out of 13
	#  8/13 Test  #8: test_key_helper ..................***Failed    0.00 sec
	[ "$CARCH" = s390x ] && return 0
	cd tests
	make
	cd ../
	ctest
}

package() {
	make DESTDIR="$pkgdir" install
}
sha512sums="19d892e13fac32022658de5eaf1db8cec3226f5f3f37a4c1c33bfa9653126ecbc6350a1ab5624025f909803c2277b86321dbea7f64e9932883cae57b65f58112  libsignal-protocol-c-2.3.3.tar.gz"
